/* -*- Mode: C; c-basic-offset: 4 -*-
 * pygtk- Python bindings for the GTK toolkit.
 * Copyright (C) 1998-2003  James Henstridge
 *
 *   gdkgc.override: gtk.gdk.GC override
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 * USA
 */
%%
override gdk_gc_new kwargs
static int
_wrap_gdk_gc_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "drawable", "foreground", "background", "font",
			      "function", "fill", "tile", "stipple",
			      "clip_mask", "subwindow_mode", "ts_x_origin",
			      "ts_y_origin", "clip_x_origin", "clip_y_origin",
			      "graphics_exposures", "line_width", "line_style",
			      "cap_style", "join_style", NULL };
    PyGObject *drawable;
    PyObject *foreground = Py_None, *background = Py_None;
    PyObject *font = Py_None;
    PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None;
    gint function = -1, fill = -1;
    gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1;
    gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1;
    gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1;
    GdkGCValues values;
    GdkGCValuesMask mask = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "O!|OOOiiOOOiiiiiiiiii:GdkGC.__init__",
				     kwlist, &PyGdkDrawable_Type, &drawable,
				     &foreground, &background, &font,
				     &function, &fill, &tile, &stipple,
				     &clip_mask, &subwindow_mode,
				     &ts_x_origin, &ts_y_origin,
				     &clip_x_origin, &clip_y_origin,
				     &graphics_exposures, &line_width,
				     &line_style, &cap_style, &join_style))
	return -1;
    if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) {
	mask |= GDK_GC_FOREGROUND;
	values.foreground = *pyg_boxed_get(foreground, GdkColor);
    } else if (foreground != Py_None) {
	PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor");
	return -1;
    }
    if (pyg_boxed_check(background, GDK_TYPE_COLOR)) {
	mask |= GDK_GC_BACKGROUND;
	values.background = *pyg_boxed_get(background, GdkColor);
    } else if (background != Py_None) {
	PyErr_SetString(PyExc_TypeError, "background must be a GdkColor");
	return -1;
    }
    if (pyg_boxed_check(font, GDK_TYPE_FONT)) {
	mask |= GDK_GC_FONT;
	values.font = pyg_boxed_get(font, GdkFont);
    } else if (font != Py_None) {
	PyErr_SetString(PyExc_TypeError, "font must be a GdkFont");
	return -1;
    }
    if (function != -1) {
	mask |= GDK_GC_FUNCTION;
	values.function = function;
    }
    if (fill != -1) {
	mask |= GDK_GC_FILL;
	values.fill = fill;
    }
    if (pygobject_check(tile, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_TILE;
	values.tile = GDK_PIXMAP(pygobject_get(tile));
    } else if (tile != Py_None) {
	PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap");
	return -1;
    }
    if (pygobject_check(stipple, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_STIPPLE;
	values.stipple = GDK_PIXMAP(pygobject_get(stipple));
    } else if (stipple != Py_None) {
	PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap");
	return -1;
    }
    if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_CLIP_MASK;
	values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask));
    } else if (clip_mask != Py_None) {
	PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap");
	return -1;
    }
    if (subwindow_mode != -1) {
	mask |= GDK_GC_SUBWINDOW;
	values.subwindow_mode = subwindow_mode;
    }
    if (ts_x_origin != -1) {
	mask |= GDK_GC_TS_X_ORIGIN;
	values.ts_x_origin = ts_x_origin;
    }
    if (ts_y_origin != -1) {
	mask |= GDK_GC_TS_Y_ORIGIN;
	values.ts_y_origin = ts_y_origin;
    }
    if (clip_x_origin != -1) {
	mask |= GDK_GC_CLIP_X_ORIGIN;
	values.clip_x_origin = clip_x_origin;
    }
    if (clip_y_origin != -1) {
	mask |= GDK_GC_CLIP_Y_ORIGIN;
	values.clip_y_origin = clip_y_origin;
    }
    if (graphics_exposures != -1) {
	mask |= GDK_GC_EXPOSURES;
	values.graphics_exposures = graphics_exposures;
    }
    if (line_width != -1) {
	mask |= GDK_GC_LINE_WIDTH;
	values.line_width = line_width;
    }
    if (line_style != -1) {
	mask |= GDK_GC_LINE_STYLE;
	values.line_style = line_style;
    }
    if (cap_style != -1) {
	mask |= GDK_GC_CAP_STYLE;
	values.cap_style = cap_style;
    }
    if (join_style != -1) {
	mask |= GDK_GC_JOIN_STYLE;
	values.join_style = join_style;
    }
    self->obj = (GObject *)gdk_gc_new_with_values(GDK_DRAWABLE(drawable->obj),
						  &values, mask);

    if (!self->obj) {
        PyErr_SetString(PyExc_RuntimeError, "could not create GdkGC object");
        return -1;
    }
    pygobject_register_wrapper((PyObject *)self);
    return 0;
}
%%
override gdk_gc_new_with_values kwargs
static PyObject *
_wrap_gdk_gc_new_with_values(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "foreground", "background", "font", "function",
                              "fill", "tile", "stipple", "clip_mask",
                              "subwindow_mode", "ts_x_origin", "ts_y_origin",
                              "clip_x_origin", "clip_y_origin",
                              "graphics_exposures", "line_width", "line_style",
                              "cap_style", "join_style", NULL };
    PyObject *foreground = Py_None, *background = Py_None;
    PyObject *font = Py_None;
    gint function = -1, fill = -1;
    PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None;
    gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1;
    gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1;
    gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1;
    GdkGCValues values;
    GdkGCValuesMask mask = 0;
    GdkGC *gc;
    PyObject *pygc;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "|OOOiiOOOiiiiiiiiii:GdkDrawable.new_gc",
                                     kwlist, &foreground, &background, &font,
                                     &function, &fill, &tile, &stipple,
                                     &clip_mask, &subwindow_mode,
                                     &ts_x_origin, &ts_y_origin,
                                     &clip_x_origin, &clip_y_origin,
                                     &graphics_exposures, &line_width,
                                     &line_style, &cap_style, &join_style))
        return NULL;
    if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) {
        mask |= GDK_GC_FOREGROUND;
        values.foreground = *pyg_boxed_get(foreground, GdkColor);
    } else if (foreground != Py_None) {
        PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor");
        return NULL;
    }
    if (pyg_boxed_check(background, GDK_TYPE_COLOR)) {
        mask |= GDK_GC_BACKGROUND;
        values.background = *pyg_boxed_get(background, GdkColor);
    } else if (background != Py_None) {
        PyErr_SetString(PyExc_TypeError, "background must be a GdkColor");
        return NULL;
    }
    if (pyg_boxed_check(font, GDK_TYPE_FONT)) {
        mask |= GDK_GC_FONT;
        values.font = pyg_boxed_get(font, GdkFont);
    } else if (font != Py_None) {
        PyErr_SetString(PyExc_TypeError, "font must be a GdkFont");
        return NULL;
    }
    if (function != -1) {
        mask |= GDK_GC_FUNCTION;
        values.function = function;
    }
    if (fill != -1) {
        mask |= GDK_GC_FILL;
        values.fill = fill;
    }
    if (pygobject_check(tile, &PyGdkPixmap_Type)) {
        mask |= GDK_GC_TILE;
        values.tile = GDK_PIXMAP(pygobject_get(tile));
    } else if (tile != Py_None) {
        PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap");
        return NULL;
    }
    if (pygobject_check(stipple, &PyGdkPixmap_Type)) {
        mask |= GDK_GC_STIPPLE;
        values.stipple = GDK_PIXMAP(pygobject_get(stipple));
    } else if (stipple != Py_None) {
        PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap");
        return NULL;
    }
    if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) {
        mask |= GDK_GC_CLIP_MASK;
        values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask));
    } else if (clip_mask != Py_None) {
        PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap");
        return NULL;
    }
    if (subwindow_mode != -1) {
        mask |= GDK_GC_SUBWINDOW;
        values.subwindow_mode = subwindow_mode;
    }
    if (ts_x_origin != -1) {
        mask |= GDK_GC_TS_X_ORIGIN;
        values.ts_x_origin = ts_x_origin;
    }
    if (ts_y_origin != -1) {
        mask |= GDK_GC_TS_Y_ORIGIN;
        values.ts_y_origin = ts_y_origin;
    }
    if (clip_x_origin != -1) {
        mask |= GDK_GC_CLIP_X_ORIGIN;
        values.clip_x_origin = clip_x_origin;
    }
    if (clip_y_origin != -1) {
        mask |= GDK_GC_CLIP_Y_ORIGIN;
        values.clip_y_origin = clip_y_origin;
    }
    if (graphics_exposures != -1) {
        mask |= GDK_GC_EXPOSURES;
        values.graphics_exposures = graphics_exposures;
    }
    if (line_width != -1) {
        mask |= GDK_GC_LINE_WIDTH;
        values.line_width = line_width;
    }
    if (line_style != -1) {
        mask |= GDK_GC_LINE_STYLE;
        values.line_style = line_style;
    }
    if (cap_style != -1) {
        mask |= GDK_GC_CAP_STYLE;
        values.cap_style = cap_style;
    }
    if (join_style != -1) {
        mask |= GDK_GC_JOIN_STYLE;
        values.join_style = join_style;
    }
    gc = gdk_gc_new_with_values(GDK_DRAWABLE(self->obj), &values, mask);
    pygc = pygobject_new((GObject *)gc);
    g_object_unref(gc);
    return pygc;
}
%%
override gdk_gc_new2 kwargs
static PyObject *
_wrap_gdk_gc_new2(PyObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "drawable", NULL };
    PyGObject *drawable;
    GdkGC *ret;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:gc_new", kwlist, &PyGdkDrawable_Type, &drawable))
        return NULL;
    if (PyErr_Warn(PyExc_DeprecationWarning, "use gdk.GC or drawable.new_gc") < 0)
        return NULL;
    ret = gdk_gc_new(GDK_DRAWABLE(drawable->obj));
    /* pygobject_new handles NULL checking */
    return pygobject_new((GObject *)ret);
}
%%
override gdk_gc_set_values kwargs
static PyObject *
_wrap_gdk_gc_set_values(PyGObject *self, PyObject *args, PyObject *kwargs)
{
    static char *kwlist[] = { "foreground", "background", "font", "function",
			      "fill", "tile", "stipple", "clip_mask",
			      "subwindow_mode", "ts_x_origin", "ts_y_origin",
			      "clip_x_origin", "clip_y_origin",
			      "graphics_exposures", "line_width", "line_style",
			      "cap_style", "join_style", NULL };
    PyObject *foreground = Py_None, *background = Py_None;
    PyObject *font = Py_None;
    gint function = -1, fill = -1;
    PyObject *tile = Py_None, *stipple = Py_None, *clip_mask = Py_None;
    gint subwindow_mode = -1, ts_x_origin = -1, ts_y_origin = -1;
    gint clip_x_origin = -1, clip_y_origin = -1, graphics_exposures = -1;
    gint line_width = -1, line_style = -1, cap_style = -1, join_style = -1;
    GdkGCValues values;
    GdkGCValuesMask mask = 0;

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				     "|OOOiiOOOiiiiiiiiii:GdkGC.set_values",
				     kwlist, &foreground, &background, &font,
				     &function, &fill, &tile, &stipple,
				     &clip_mask, &subwindow_mode,
				     &ts_x_origin, &ts_y_origin,
				     &clip_x_origin, &clip_y_origin,
				     &graphics_exposures, &line_width,
				     &line_style, &cap_style, &join_style))
	return NULL;
    if (pyg_boxed_check(foreground, GDK_TYPE_COLOR)) {
	mask |= GDK_GC_FOREGROUND;
	values.foreground = *pyg_boxed_get(foreground, GdkColor);
    } else if (foreground != Py_None) {
	PyErr_SetString(PyExc_TypeError, "foreground must be a GdkColor");
	return NULL;
    }
    if (pyg_boxed_check(background, GDK_TYPE_COLOR)) {
	mask |= GDK_GC_BACKGROUND;
	values.background = *pyg_boxed_get(background, GdkColor);
    } else if (background != Py_None) {
	PyErr_SetString(PyExc_TypeError, "background must be a GdkColor");
	return NULL;
    }
    if (pyg_boxed_check(font, GDK_TYPE_FONT)) {
	mask |= GDK_GC_FONT;
	values.font = pyg_boxed_get(font, GdkFont);
    } else if (font != Py_None) {
	PyErr_SetString(PyExc_TypeError, "font must be a GdkFont");
	return NULL;
    }
    if (function != -1) {
	mask |= GDK_GC_FUNCTION;
	values.function = function;
    }
    if (fill != -1) {
	mask |= GDK_GC_FILL;
	values.fill = fill;
    }
    if (pygobject_check(tile, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_TILE;
	values.tile = GDK_PIXMAP(pygobject_get(tile));
    } else if (tile != Py_None) {
	PyErr_SetString(PyExc_TypeError, "tile must be a GdkPixmap");
	return NULL;
    }
    if (pygobject_check(stipple, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_STIPPLE;
	values.stipple = GDK_PIXMAP(pygobject_get(stipple));
    } else if (stipple != Py_None) {
	PyErr_SetString(PyExc_TypeError, "stipple must be a GdkPixmap");
	return NULL;
    }
    if (pygobject_check(clip_mask, &PyGdkPixmap_Type)) {
	mask |= GDK_GC_CLIP_MASK;
	values.clip_mask = GDK_PIXMAP(pygobject_get(clip_mask));
    } else if (clip_mask != Py_None) {
	PyErr_SetString(PyExc_TypeError, "clip_mask must be a GdkPixmap");
	return NULL;
    }
    if (subwindow_mode != -1) {
	mask |= GDK_GC_SUBWINDOW;
	values.subwindow_mode = subwindow_mode;
    }
    if (ts_x_origin != -1) {
	mask |= GDK_GC_TS_X_ORIGIN;
	values.ts_x_origin = ts_x_origin;
    }
    if (ts_y_origin != -1) {
	mask |= GDK_GC_TS_Y_ORIGIN;
	values.ts_y_origin = ts_y_origin;
    }
    if (clip_x_origin != -1) {
	mask |= GDK_GC_CLIP_X_ORIGIN;
	values.clip_x_origin = clip_x_origin;
    }
    if (clip_y_origin != -1) {
	mask |= GDK_GC_CLIP_Y_ORIGIN;
	values.clip_y_origin = clip_y_origin;
    }
    if (graphics_exposures != -1) {
	mask |= GDK_GC_EXPOSURES;
	values.graphics_exposures = graphics_exposures;
    }
    if (line_width != -1) {
	mask |= GDK_GC_LINE_WIDTH;
	values.line_width = line_width;
    }
    if (line_style != -1) {
	mask |= GDK_GC_LINE_STYLE;
	values.line_style = line_style;
    }
    if (cap_style != -1) {
	mask |= GDK_GC_CAP_STYLE;
	values.cap_style = cap_style;
    }
    if (join_style != -1) {
	mask |= GDK_GC_JOIN_STYLE;
	values.join_style = join_style;
    }
    gdk_gc_set_values(GDK_GC(self->obj), &values, mask);

    Py_INCREF(Py_None);
    return Py_None;
}
%%
override-slot GdkGC.tp_getattro
static PyObject *
_wrap_gdk_gc_tp_getattro(PyGObject *self, PyObject *py_attr)
{
    GdkGCValues gc;
    char *attr;

    if (PyString_Check(py_attr))
        attr = PyString_AsString(py_attr);
    else
        return PyObject_GenericGetAttr((PyObject *)self, py_attr);

    if (!strcmp(attr, "__members__"))
        return Py_BuildValue("[ssssssssssssssssss]", "background", "cap_style",
                             "clip_mask", "clip_x_origin", "clip_y_origin",
                             "fill", "font", "foreground", "function",
                             "graphics_exposures", "join_style", "line_style",
                             "line_width", "stipple", "sub_window", "tile",
                             "ts_x_origin", "ts_y_origin");
    gdk_gc_get_values(GDK_GC(self->obj), &gc);
    if (!strcmp(attr, "foreground")) 
        return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.foreground), TRUE, TRUE);
    if (!strcmp(attr, "background")) 
        return pyg_boxed_new(GDK_TYPE_COLOR, &(gc.background), TRUE, TRUE);
    if (!strcmp(attr, "font")) 
        return pyg_boxed_new(GDK_TYPE_FONT, gc.font, TRUE, TRUE);
    if (!strcmp(attr, "function")) 
        return PyInt_FromLong(gc.function);
    if (!strcmp(attr, "fill")) 
        return PyInt_FromLong(gc.fill);
    if (!strcmp(attr, "tile")) 
        return pygobject_new((GObject *)gc.tile);
    if (!strcmp(attr, "stipple")) 
        return pygobject_new((GObject *)gc.stipple);
    if (!strcmp(attr, "clip_mask")) 
        return pygobject_new((GObject *)gc.clip_mask);
    if (!strcmp(attr, "subwindow_mode"))
        return pyg_enum_from_gtype(GDK_TYPE_SUBWINDOW_MODE, gc.subwindow_mode);
    if (!strcmp(attr, "ts_x_origin")) 
        return PyInt_FromLong(gc.ts_x_origin);
    if (!strcmp(attr, "ts_y_origin")) 
        return PyInt_FromLong(gc.ts_y_origin);
    if (!strcmp(attr, "clip_x_origin")) 
        return PyInt_FromLong(gc.clip_x_origin);
    if (!strcmp(attr, "clip_y_origin")) 
        return PyInt_FromLong(gc.clip_y_origin);
    if (!strcmp(attr, "graphics_exposures"))
        return PyInt_FromLong(gc.graphics_exposures);
    if (!strcmp(attr, "line_width")) 
        return PyInt_FromLong(gc.line_width);
    if (!strcmp(attr, "line_style")) 
        return pyg_enum_from_gtype(GDK_TYPE_LINE_STYLE, gc.line_style);
    if (!strcmp(attr, "cap_style")) 
        return pyg_enum_from_gtype(GDK_TYPE_CAP_STYLE, gc.cap_style);
    if (!strcmp(attr, "join_style")) 
        return pyg_enum_from_gtype(GDK_TYPE_JOIN_STYLE, gc.join_style);

    {
        PyObject *name = PyString_FromString(attr);
        PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, name);
        Py_DECREF(name);
        return ret;
    }
}
%%
override-slot GdkGC.tp_setattro
static int
_wrap_gdk_gc_tp_setattro(PyGObject *self, PyObject *py_attr, PyObject *value)
{
    GdkGC *gc = GDK_GC(self->obj);
    char *attr;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "can't delete attributes");
        return -1;
    }

    if (PyString_Check(py_attr))
        attr = PyString_AsString(py_attr);
    else {
        PyErr_SetString(PyExc_AttributeError, "could not write attribute");
        return -1;
    }

    if (PyInt_Check(value)) {
        int i = PyInt_AsLong(value);
        GdkGCValues v;
        gdk_gc_get_values(gc, &v);
        if (!strcmp(attr, "function")) {
            gdk_gc_set_function(gc, i);
            return 0;
        } else if (!strcmp(attr, "fill")) {
            gdk_gc_set_fill(gc, i);
            return 0;
        } else if (!strcmp(attr, "subwindow_mode")) {
            gdk_gc_set_subwindow(gc, i);
            return 0;
        } else if (!strcmp(attr, "ts_x_origin")) {
            gdk_gc_set_ts_origin(gc, i, v.ts_y_origin);
            return 0;
        } else if (!strcmp(attr, "ts_y_origin")) {
            gdk_gc_set_ts_origin(gc, v.ts_x_origin, i);
            return 0;
        } else if (!strcmp(attr, "clip_x_origin")) {
            gdk_gc_set_clip_origin(gc, i, v.clip_y_origin);
            return 0;
        } else if (!strcmp(attr, "clip_y_origin")) {
            gdk_gc_set_clip_origin(gc, v.clip_x_origin, i);
            return 0;
        } else if (!strcmp(attr, "graphics_exposures")) {
            gdk_gc_set_exposures(gc, i);
            return 0;
        } else if (!strcmp(attr, "line_width")) {
            gdk_gc_set_line_attributes(gc, i, v.line_style,
                                       v.cap_style, v.join_style);
            return 0;
        } else if (!strcmp(attr, "line_style")) {
            gdk_gc_set_line_attributes(gc, v.line_width, i,
                                       v.cap_style, v.join_style);
            return 0;
        } else if (!strcmp(attr, "cap_style")) {
            gdk_gc_set_line_attributes(gc, v.line_width, v.line_style,
                                       i, v.join_style);
            return 0;
        } else if (!strcmp(attr, "join_style")) {
            gdk_gc_set_line_attributes(gc, v.line_width, v.line_style,
                                       v.cap_style, i);
            return 0;
        }
    } else if (pyg_boxed_check(value, GDK_TYPE_COLOR)) {
        GdkColor *c = pyg_boxed_get(value, GdkColor);
        if (!strcmp(attr, "foreground")) {
            gdk_gc_set_foreground(gc, c);
            return 0;
        } else if (!strcmp(attr, "background")) {
            gdk_gc_set_background(gc, c);
            return 0;
        }
    } else if (pyg_boxed_check(value, GDK_TYPE_FONT)) {
        if (!strcmp(attr, "font")) {
            gdk_gc_set_font(gc, pyg_boxed_get(value, GdkFont));
            return 0;
        }
    } else if (pygobject_check(value, &PyGdkWindow_Type) || value == Py_None) {
        PyGObject *window = (PyGObject *)value;
        GdkWindow *w = (value==Py_None)?NULL:GDK_WINDOW(window->obj);
        if (!strcmp(attr, "tile")) {
            gdk_gc_set_tile(gc, w);
            return 0;
        } else if (!strcmp(attr, "stipple")) {
            gdk_gc_set_stipple(gc, w);
            return 0;
        } else if (!strcmp(attr, "clip_mask")) {
            gdk_gc_set_clip_mask(gc, w);
            return 0;
        }
    }

    PyErr_SetString(PyExc_AttributeError, "could not write attribute");
    return -1;
}
%%
override gdk_gc_set_dashes
static PyObject *
_wrap_gdk_gc_set_dashes(PyGObject *self, PyObject *args)
{
    gint dash_offset, n, i;
    PyObject *list;
    gint8 *dash_list;

    if (!PyArg_ParseTuple(args, "iO:GdkGC.set_dashes", &dash_offset, &list))
        return NULL;
    if (!PySequence_Check(list)) {
        PyErr_SetString(PyExc_TypeError, "second argument must be a sequence");
        return NULL;
    }
    n = PySequence_Length(list);
    dash_list = g_new(gint8, n);
    for (i = 0; i < n; i++) {
        PyObject *item = PySequence_GetItem(list, i);
        Py_DECREF(item);

        if (!PyInt_Check(item)) {
            PyErr_SetString(PyExc_TypeError, "sequence member must be an int");
            g_free(dash_list);
            return NULL;
        }
        dash_list[i] = (gint8)PyInt_AsLong(item);
        if (dash_list[i] == 0) {
            PyErr_SetString(PyExc_TypeError, "sequence member must not be 0");
            g_free(dash_list);
            return NULL;
        }
    }
    gdk_gc_set_dashes(GDK_GC(self->obj), dash_offset, dash_list, n);
    g_free(dash_list);
    Py_INCREF(Py_None);
    return Py_None;
}
